home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / cp / error.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  33KB  |  1,459 lines

  1. /* Call-backs for C++ error reporting.
  2.    This code is non-reentrant.
  3.    Copyright (C) 1993 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22. #include "config.h"
  23. #include "tree.h"
  24. #include "cp-tree.h"
  25. #include "obstack.h"
  26. #include <ctype.h>
  27.  
  28. typedef char* cp_printer ();
  29.  
  30. #define A args_as_string
  31. #define C code_as_string
  32. #define D decl_as_string
  33. #define E expr_as_string
  34. #define L language_as_string
  35. #define O op_as_string
  36. #define P parm_as_string
  37. #define T type_as_string
  38.  
  39. #define _ (cp_printer *) 0
  40. cp_printer * cp_printers[256] =
  41. /*0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F */
  42.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x00 */
  43.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x10 */
  44.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x20 */
  45.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x30 */
  46.   _, A, _, C, D, E, _, _, _, _, _, _, L, _, _, O, /* 0x40 */
  47.   P, _, _, _, T, _, _, _, _, _, _, _, _, _, _, _, /* 0x50 */
  48.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */
  49.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */
  50. };
  51. #undef C
  52. #undef D
  53. #undef E
  54. #undef L
  55. #undef O
  56. #undef P
  57. #undef T
  58. #undef _
  59.  
  60. #define obstack_chunk_alloc xmalloc
  61. #define obstack_chunk_free free
  62.  
  63. /* Obstack where we build text strings for overloading, etc.  */
  64. static struct obstack scratch_obstack;
  65. static char *scratch_firstobj;
  66.  
  67. # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
  68. # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
  69. # define OB_PUTC2(C1,C2)    \
  70.   (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
  71. # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
  72. # define OB_PUTID(ID)  \
  73.   (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID),    \
  74.          IDENTIFIER_LENGTH (ID)))
  75. # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
  76. # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
  77. # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
  78.                OB_PUTCP (digit_buffer); } while (0)
  79. # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
  80.  
  81. # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
  82.  
  83. static void dump_type (), dump_decl (), dump_function_decl ();
  84. static void dump_expr (), dump_unary_op (), dump_binary_op ();
  85. static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix ();
  86. static void dump_function_name ();
  87.  
  88. void
  89. init_error ()
  90. {
  91.   gcc_obstack_init (&scratch_obstack);
  92.   scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
  93. }
  94.  
  95. enum pad { none, before, after };
  96.  
  97. static void
  98. dump_readonly_or_volatile (t, p)
  99.      tree t;
  100.      enum pad p;
  101. {
  102.   if (TYPE_READONLY (t) || TYPE_VOLATILE (t))
  103.     {
  104.       if (p == before) OB_PUTC (' ');
  105.       if (TYPE_READONLY (t))
  106.     OB_PUTS ("const");
  107.       if (TYPE_READONLY (t) && TYPE_VOLATILE (t))
  108.     OB_PUTC (' ');
  109.       if (TYPE_VOLATILE (t))
  110.     OB_PUTS ("volatile");
  111.       if (p == after) OB_PUTC (' ');
  112.     }
  113. }
  114.  
  115. /* This must be large enough to hold any printed integer or floating-point
  116.    value.  */
  117. static char digit_buffer[128];
  118.  
  119. /* Dump into the obstack a human-readable equivalent of TYPE. */
  120. static void
  121. dump_type (t, v)
  122.      tree t;
  123.      int v;            /* verbose? */
  124. {
  125.   if (t == NULL_TREE)
  126.     return;
  127.   
  128.   if (TYPE_PTRMEMFUNC_P (t))
  129.     goto offset_type;
  130.  
  131.   switch (TREE_CODE (t))
  132.     {
  133.     case ERROR_MARK:
  134.       OB_PUTS ("{error}");
  135.       break;
  136.  
  137.     case UNKNOWN_TYPE:
  138.       OB_PUTS ("{unknown type}");
  139.       break;
  140.  
  141.     case TREE_LIST:
  142.       /* i.e. function taking no arguments */
  143.       if (t != void_list_node)
  144.     {
  145.       dump_type (TREE_VALUE (t), v);
  146.       /* Can this happen other than for default arguments? */
  147.       if (TREE_PURPOSE (t) && v)
  148.         {
  149.           OB_PUTS (" = ");
  150.           dump_expr (TREE_PURPOSE (t));
  151.         }
  152.       if (TREE_CHAIN (t))
  153.         {
  154.           if (TREE_CHAIN (t) != void_list_node)
  155.         {
  156.           OB_PUTC2 (',', ' ');
  157.           dump_type (TREE_CHAIN (t), v);
  158.         }
  159.         }
  160.       else OB_PUTS (" ...");
  161.     }
  162.       break;
  163.  
  164.     case IDENTIFIER_NODE:
  165.       OB_PUTID (t);
  166.       break;
  167.  
  168.     case TREE_VEC:
  169.       dump_type (BINFO_TYPE (t), v);
  170.       break;
  171.  
  172.     case RECORD_TYPE:
  173.     case UNION_TYPE:
  174.     case ENUMERAL_TYPE:
  175.       if (TYPE_LANG_SPECIFIC (t)
  176.       && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
  177.     {
  178.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  179.         dump_readonly_or_volatile (t);
  180.       dump_type (SIGNATURE_TYPE (t), v);
  181.       if (IS_SIGNATURE_POINTER (t))
  182.         OB_PUTC ('*');
  183.       else
  184.         OB_PUTC ('&');
  185.     }
  186.       else
  187.     dump_aggr_type (t, v);
  188.       break;
  189.  
  190.     case TYPE_DECL:
  191.       dump_decl (t, v);
  192.       break;
  193.  
  194.     case INTEGER_TYPE:
  195.       if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
  196.     OB_PUTS ("unsigned ");
  197.       else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
  198.     OB_PUTS ("signed ");
  199.  
  200.       /* fall through.  */
  201.     case REAL_TYPE:
  202.     case VOID_TYPE:
  203.     case BOOLEAN_TYPE:
  204.       dump_readonly_or_volatile (t, after);
  205.       OB_PUTID (TYPE_IDENTIFIER (t));
  206.       break;
  207.  
  208.     case TEMPLATE_TYPE_PARM:
  209.       OB_PUTID (TYPE_IDENTIFIER (t));
  210.       break;
  211.  
  212.     case UNINSTANTIATED_P_TYPE:
  213.       OB_PUTID (DECL_NAME (UPT_TEMPLATE (t)));
  214.       OB_PUTS ("<...>");
  215.       break;
  216.  
  217.       /* This is not always necessary for pointers and such, but doing this
  218.      reduces code size.  */
  219.     case ARRAY_TYPE:
  220.     case POINTER_TYPE:
  221.     case REFERENCE_TYPE:
  222.     case OFFSET_TYPE:
  223.     offset_type:
  224.     case FUNCTION_TYPE:
  225.     case METHOD_TYPE:
  226.       dump_type_prefix (t, v);
  227.       dump_type_suffix (t, v);
  228.       break;
  229.  
  230.     default:
  231.       sorry ("`%s' not supported by dump_type",
  232.          tree_code_name[(int) TREE_CODE (t)]);
  233.     }
  234. }
  235.  
  236. static char *
  237. aggr_variety (t)
  238.      tree t;
  239. {
  240.   if (TREE_CODE (t) == ENUMERAL_TYPE)
  241.     return "enum";
  242.   else if (TREE_CODE (t) == UNION_TYPE)
  243.     return "union";
  244.   else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
  245.     return "class";
  246.   else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
  247.     return "signature";
  248.   else
  249.     return "struct";
  250. }
  251.  
  252. /* Print out a class declaration, in the form `class foo'. */
  253. static void
  254. dump_aggr_type (t, v)
  255.      tree t;
  256.      int v;            /* verbose? */
  257. {
  258.   tree name;
  259.   char *variety = aggr_variety (t);
  260.  
  261.   dump_readonly_or_volatile (t, after);
  262.  
  263.   if (v > 0)
  264.     {
  265.       OB_PUTCP (variety);
  266.       OB_PUTC (' ');
  267.     }
  268.   
  269.   name = TYPE_NAME (t);
  270.  
  271.   if (DECL_CONTEXT (name))
  272.     {
  273.       /* FUNCTION_DECL or RECORD_TYPE */
  274.       dump_decl (DECL_CONTEXT (name), 0);
  275.       OB_PUTC2 (':', ':');
  276.     }
  277.  
  278.   /* kludge around weird behavior on g++.brendan/line1.C */
  279.   if (TREE_CODE (name) != IDENTIFIER_NODE)
  280.     name = DECL_NAME (name);
  281.  
  282.   if (ANON_AGGRNAME_P (name))
  283.     {
  284.       OB_PUTS ("{anonymous");
  285.       if (!v)
  286.     {
  287.       OB_PUTC (' ');
  288.       OB_PUTCP (variety);
  289.     }
  290.       OB_PUTC ('}');
  291.     }
  292.   else
  293.     OB_PUTID (name);
  294. }
  295.  
  296. /* Dump into the obstack the initial part of the output for a given type.
  297.    This is necessary when dealing with things like functions returning
  298.    functions.  Examples:
  299.  
  300.    return type of `int (* fee ())()': pointer -> function -> int.  Both
  301.    pointer (and reference and offset) and function (and member) types must
  302.    deal with prefix and suffix.
  303.  
  304.    Arrays must also do this for DECL nodes, like int a[], and for things like
  305.    int *[]&.  */
  306.  
  307. static void
  308. dump_type_prefix (t, v)
  309.      tree t;
  310.      int v;            /* verbosity */
  311. {
  312.   if (TYPE_PTRMEMFUNC_P (t))
  313.     {
  314.       t = TYPE_PTRMEMFUNC_FN_TYPE (t);
  315.       goto offset_type;
  316.     }
  317.   
  318.   switch (TREE_CODE (t))
  319.     {
  320.     case POINTER_TYPE:
  321.       {
  322.     tree sub = TREE_TYPE (t);
  323.     
  324.     dump_type_prefix (sub, v);
  325.     /* A tree for a member pointer looks like pointer to offset,
  326.        so let the OFFSET_TYPE case handle it.  */
  327.     if (TREE_CODE (sub) != OFFSET_TYPE)
  328.       {
  329.         switch (TREE_CODE (sub))
  330.           {
  331.         /* We don't want int ( *)() */
  332.           case FUNCTION_TYPE:
  333.           case METHOD_TYPE:
  334.         break;
  335.         
  336.           case ARRAY_TYPE:
  337.         OB_PUTC2 (' ', '(');
  338.         break;
  339.  
  340.           case POINTER_TYPE:
  341.         /* We don't want "char * *" */
  342.         if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
  343.           break;
  344.         /* But we do want "char *const *" */
  345.         
  346.           default:
  347.         OB_PUTC (' ');
  348.           }
  349.         OB_PUTC ('*');
  350.         dump_readonly_or_volatile (t, none);
  351.       }
  352.       }
  353.       break;
  354.  
  355.     case REFERENCE_TYPE:
  356.       {
  357.     tree sub = TREE_TYPE (t);
  358.     dump_type_prefix (sub, v);
  359.  
  360.     switch (TREE_CODE (sub))
  361.       {
  362.       case ARRAY_TYPE:
  363.         OB_PUTC2 (' ', '(');
  364.         break;
  365.  
  366.       case POINTER_TYPE:
  367.         /* We don't want "char * &" */
  368.         if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
  369.           break;
  370.         /* But we do want "char *const &" */
  371.  
  372.       default:
  373.         OB_PUTC (' ');
  374.       }
  375.       }
  376.       OB_PUTC ('&');
  377.       dump_readonly_or_volatile (t, none);
  378.       break;
  379.  
  380.     case OFFSET_TYPE:
  381.     offset_type:
  382.       dump_type_prefix (TREE_TYPE (t), v);
  383.       if (TREE_CODE (t) == OFFSET_TYPE)    /* pmfs deal with this in d_t_p */
  384.     {
  385.       OB_PUTC (' ');
  386.       dump_type (TYPE_OFFSET_BASETYPE (t), 0);
  387.       OB_PUTC2 (':', ':');
  388.     }
  389.       OB_PUTC ('*');
  390.       dump_readonly_or_volatile (t, none);
  391.       break;
  392.  
  393.       /* Can only be reached through function pointer -- this would not be
  394.          correct if FUNCTION_DECLs used it.  */
  395.     case FUNCTION_TYPE:
  396.       dump_type_prefix (TREE_TYPE (t), v);
  397.       OB_PUTC2 (' ', '(');
  398.       break;
  399.  
  400.     case METHOD_TYPE:
  401.       dump_type_prefix (TREE_TYPE (t), v);
  402.       OB_PUTC2 (' ', '(');
  403.       dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0);
  404.       OB_PUTC2 (':', ':');
  405.       break;
  406.  
  407.     case ARRAY_TYPE:
  408.       dump_type_prefix (TREE_TYPE (t), v);
  409.       break;
  410.  
  411.     case ENUMERAL_TYPE:
  412.     case ERROR_MARK:
  413.     case IDENTIFIER_NODE:
  414.     case INTEGER_TYPE:
  415.     case BOOLEAN_TYPE:
  416.     case REAL_TYPE:
  417.     case RECORD_TYPE:
  418.     case TEMPLATE_TYPE_PARM:
  419.     case TREE_LIST:
  420.     case TYPE_DECL:
  421.     case TREE_VEC:
  422.     case UNINSTANTIATED_P_TYPE:
  423.     case UNION_TYPE:
  424.     case UNKNOWN_TYPE:
  425.     case VOID_TYPE:
  426.       dump_type (t, v);
  427.       break;
  428.       
  429.     default:
  430.       sorry ("`%s' not supported by dump_type_prefix",
  431.          tree_code_name[(int) TREE_CODE (t)]);
  432.     }
  433. }
  434.  
  435. static void
  436. dump_type_suffix (t, v)
  437.      tree t;
  438.      int v;            /* verbose? */
  439. {
  440.   if (TYPE_PTRMEMFUNC_P (t))
  441.     t = TYPE_PTRMEMFUNC_FN_TYPE (t);
  442.  
  443.   switch (TREE_CODE (t))
  444.     {
  445.     case POINTER_TYPE:
  446.     case REFERENCE_TYPE:
  447.     case OFFSET_TYPE:
  448.       if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
  449.     OB_PUTC (')');
  450.       dump_type_suffix (TREE_TYPE (t), v);
  451.       break;
  452.  
  453.       /* Can only be reached through function pointer */
  454.     case FUNCTION_TYPE:
  455.     case METHOD_TYPE:
  456.       {
  457.     tree arg;
  458.     OB_PUTC2 (')', '(');
  459.     arg = TYPE_ARG_TYPES (t);
  460.     if (TREE_CODE (t) == METHOD_TYPE)
  461.       arg = TREE_CHAIN (arg);
  462.  
  463.     if (arg)
  464.       dump_type (arg, v);
  465.     else
  466.       OB_PUTS ("...");
  467.     OB_PUTC (')');
  468.     if (TREE_CODE (t) == METHOD_TYPE)
  469.       dump_readonly_or_volatile
  470.         (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
  471.     dump_type_suffix (TREE_TYPE (t), v);
  472.     break;
  473.       }
  474.  
  475.     case ARRAY_TYPE:
  476.       OB_PUTC ('[');
  477.       if (TYPE_DOMAIN (t))
  478.     OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
  479.       OB_PUTC (']');
  480.       dump_type_suffix (TREE_TYPE (t), v);
  481.       break;
  482.       
  483.     case ENUMERAL_TYPE:
  484.     case ERROR_MARK:
  485.     case IDENTIFIER_NODE:
  486.     case INTEGER_TYPE:
  487.     case BOOLEAN_TYPE:
  488.     case REAL_TYPE:
  489.     case RECORD_TYPE:
  490.     case TEMPLATE_TYPE_PARM:
  491.     case TREE_LIST:
  492.     case TYPE_DECL:
  493.     case TREE_VEC:
  494.     case UNINSTANTIATED_P_TYPE:
  495.     case UNION_TYPE:
  496.     case UNKNOWN_TYPE:
  497.     case VOID_TYPE:
  498.       break;
  499.  
  500.     default:
  501.       sorry ("`%s' not supported by dump_type_suffix",
  502.          tree_code_name[(int) TREE_CODE (t)]);
  503.     }
  504. }
  505.  
  506. /* Return a function declaration which corresponds to the IDENTIFIER_NODE
  507.    argument.  */
  508. tree
  509. ident_fndecl (t)
  510.      tree t;
  511. {
  512.   tree n = lookup_name (t, 0);
  513.  
  514.   if (TREE_CODE (n) == FUNCTION_DECL)
  515.     return n;
  516.   else if (TREE_CODE (n) == TREE_LIST
  517.        && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
  518.     return TREE_VALUE (n);
  519.  
  520.   my_friendly_abort (66);
  521.   return NULL_TREE;
  522. }
  523.  
  524. #ifndef NO_DOLLAR_IN_LABEL
  525. #  define GLOBAL_THING "_GLOBAL_$"
  526. #else
  527. #  ifndef NO_DOT_IN_LABEL
  528. #    define GLOBAL_THING "_GLOBAL_."
  529. #  else
  530. #    define GLOBAL_THING "_GLOBAL__"
  531. #  endif
  532. #endif
  533.  
  534. #define GLOBAL_IORD_P(NODE) \
  535.   !strncmp(IDENTIFIER_POINTER(NODE),GLOBAL_THING,sizeof(GLOBAL_THING)-1)
  536.  
  537. void
  538. dump_global_iord (t)
  539.      tree t;
  540. {
  541.   char *name = IDENTIFIER_POINTER (t);
  542.  
  543.   OB_PUTS ("(static ");
  544.   if (name [sizeof (GLOBAL_THING) - 1] == 'I')
  545.     OB_PUTS ("initializers");
  546.   else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
  547.     OB_PUTS ("destructors");
  548.   else
  549.     my_friendly_abort (352);
  550.   
  551.   OB_PUTS (" for ");
  552.   OB_PUTCP (input_filename);
  553.   OB_PUTC (')');
  554. }
  555.  
  556. static void
  557. dump_decl (t, v)
  558.      tree t;
  559.      int v;            /* verbosity */
  560. {
  561.   if (t == NULL_TREE)
  562.     return;
  563.  
  564.   switch (TREE_CODE (t))
  565.     {
  566.     case ERROR_MARK:
  567.       OB_PUTS (" /* decl error */ ");
  568.       break;
  569.  
  570.     case TYPE_DECL:
  571.       {
  572.     /* Don't say 'typedef class A' */
  573.     tree type = TREE_TYPE (t);
  574.         if (((IS_AGGR_TYPE (type) && ! TYPE_PTRMEMFUNC_P (type))
  575.          || TREE_CODE (type) == ENUMERAL_TYPE)
  576.         && type == TYPE_MAIN_VARIANT (type))
  577.       {
  578.         dump_type (type, v);
  579.         break;
  580.       }
  581.       }
  582.       if (v > 0)
  583.     OB_PUTS ("typedef ");
  584.       goto general;
  585.       break;
  586.       
  587.     case VAR_DECL:
  588.       if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
  589.     {
  590.       OB_PUTS ("vtable for ");
  591.       dump_type (DECL_CONTEXT (t), v);
  592.       break;
  593.     }
  594.       /* else fall through */
  595.     case FIELD_DECL:
  596.     case PARM_DECL:
  597.     general:
  598.       if (v > 0)
  599.     {
  600.       dump_type_prefix (TREE_TYPE (t), v);
  601.       OB_PUTC (' ');
  602.       dump_readonly_or_volatile (t, after);
  603.     }
  604.       /* DECL_CLASS_CONTEXT isn't being set in some cases.  Hmm...  */
  605.       if (DECL_CONTEXT (t)
  606.       && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't')
  607.     {
  608.       dump_type (DECL_CONTEXT (t), 0);
  609.       OB_PUTC2 (':', ':');
  610.     }
  611.       if (DECL_NAME (t))
  612.     dump_decl (DECL_NAME (t), v);
  613.       else
  614.     OB_PUTS ("{anon}");
  615.       if (v > 0)
  616.     dump_type_suffix (TREE_TYPE (t), v);
  617.       break;
  618.  
  619.     case NAMESPACE_DECL:
  620.       OB_PUTID (DECL_NAME (t));
  621.       break;
  622.  
  623.     case ARRAY_REF:
  624.       dump_decl (TREE_OPERAND (t, 0), v);
  625.       OB_PUTC ('[');
  626.       dump_decl (TREE_OPERAND (t, 1), v);
  627.       OB_PUTC (']');
  628.       break;
  629.  
  630.       /* So that we can do dump_decl in dump_aggr_type and have it work for
  631.      both class and function scope.  */
  632.     case RECORD_TYPE:
  633.     case UNION_TYPE:
  634.     case ENUMERAL_TYPE:
  635.       dump_type (t, v);
  636.       break;
  637.  
  638.     case TYPE_EXPR:
  639.       my_friendly_abort (69);
  640.       break;
  641.  
  642.       /* These special cases are duplicated here so that other functions
  643.      can feed identifiers to cp_error and get them demangled properly. */
  644.     case IDENTIFIER_NODE:
  645.       if (DESTRUCTOR_NAME_P (t))
  646.     {
  647.       OB_PUTC ('~');
  648.       dump_decl (DECL_NAME (ident_fndecl (t)), 0);
  649.     }
  650.       else if (IDENTIFIER_TYPENAME_P (t))
  651.     {
  652.       OB_PUTS ("operator ");
  653.       /* Not exactly IDENTIFIER_TYPE_VALUE.  */
  654.       dump_type (TREE_TYPE (t), 0);
  655.       break;
  656.     }
  657.       else if (IDENTIFIER_OPNAME_P (t))
  658.     {
  659.       char *name_string = operator_name_string (t);
  660.       OB_PUTS ("operator ");
  661.       OB_PUTCP (name_string);
  662.     }
  663.       else
  664.     OB_PUTID (t);
  665.       break;
  666.  
  667.     case FUNCTION_DECL:
  668.       if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
  669.     dump_global_iord (DECL_ASSEMBLER_NAME (t));
  670.       else
  671.     dump_function_decl (t, v);
  672.       break;
  673.  
  674.     case TEMPLATE_DECL:
  675.       {
  676.     tree args = DECL_TEMPLATE_PARMS (t);
  677.     int i, len = args ? TREE_VEC_LENGTH (args) : 0;
  678.     OB_PUTS ("template <");
  679.     for (i = 0; i < len; i++)
  680.       {
  681.         tree arg = TREE_VEC_ELT (args, i);
  682.         tree defval = TREE_PURPOSE (arg);
  683.         arg = TREE_VALUE (arg);
  684.         if (TREE_CODE (arg) == TYPE_DECL)
  685.           {
  686.         OB_PUTS ("class ");
  687.         OB_PUTID (DECL_NAME (arg));
  688.           }
  689.         else
  690.           dump_decl (arg, 1);
  691.  
  692.         if (defval)
  693.           {
  694.         OB_PUTS (" = ");
  695.         dump_decl (defval, 1);
  696.           }
  697.         
  698.         OB_PUTC2 (',', ' ');
  699.       }
  700.     if (len != 0)
  701.       OB_UNPUT (2);
  702.     OB_PUTC2 ('>', ' ');
  703.  
  704.     if (DECL_TEMPLATE_IS_CLASS (t))
  705.       {
  706.         OB_PUTS ("class ");
  707.         OB_PUTID (DECL_NAME (t));
  708.       }
  709.     else switch (NEXT_CODE (t))
  710.       {
  711.       case METHOD_TYPE:
  712.       case FUNCTION_TYPE:
  713.         dump_function_decl (t, v);
  714.         break;
  715.  
  716.       default:
  717.         my_friendly_abort (353);
  718.       }
  719.       }
  720.       break;
  721.  
  722.     case LABEL_DECL:
  723.       OB_PUTID (DECL_NAME (t));
  724.       break;
  725.  
  726.     case CONST_DECL:
  727.       if (NEXT_CODE (t) == ENUMERAL_TYPE)
  728.     goto general;
  729.       else
  730.     dump_expr (DECL_INITIAL (t), 0);
  731.       break;
  732.  
  733.     default:
  734.       sorry ("`%s' not supported by dump_decl",
  735.          tree_code_name[(int) TREE_CODE (t)]);
  736.     }
  737. }
  738.  
  739. /* Pretty printing for announce_function.  T is the declaration of the
  740.    function we are interested in seeing.  V is non-zero if we should print
  741.    the type that this function returns.  */
  742.  
  743. static void
  744. dump_function_decl (t, v)
  745.      tree t;
  746.      int v;
  747. {
  748.   tree name = DECL_ASSEMBLER_NAME (t);
  749.   tree fntype = TREE_TYPE (t);
  750.   tree parmtypes = TYPE_ARG_TYPES (fntype);
  751.   tree cname = NULL_TREE;
  752.  
  753.   /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT.  */
  754.   if (DECL_CONTEXT (t))
  755.     cname = DECL_CLASS_CONTEXT (t);
  756.   /* this is for partially instantiated template methods */
  757.   else if (TREE_CODE (fntype) == METHOD_TYPE)
  758.     cname = TREE_TYPE (TREE_VALUE (parmtypes));
  759.  
  760.   v = (v > 0);
  761.   
  762.   if (v)
  763.     {
  764.       if (DECL_STATIC_FUNCTION_P (t))
  765.     OB_PUTS ("static ");
  766.     
  767.       if (! IDENTIFIER_TYPENAME_P (name)
  768.       && ! DECL_CONSTRUCTOR_P (t)
  769.       && ! DESTRUCTOR_NAME_P (name))
  770.     {
  771.       dump_type_prefix (TREE_TYPE (fntype), 1);
  772.       OB_PUTC (' ');
  773.     }
  774.     }
  775.  
  776.   if (cname)
  777.     {
  778.       dump_type (cname, 0);
  779.       OB_PUTC2 (':', ':');
  780.       if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
  781.     parmtypes = TREE_CHAIN (parmtypes);
  782.       if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
  783.     /* Skip past "in_charge" identifier.  */
  784.     parmtypes = TREE_CHAIN (parmtypes);
  785.     }
  786.  
  787.   if (DESTRUCTOR_NAME_P (name))
  788.     parmtypes = TREE_CHAIN (parmtypes);
  789.   
  790.   dump_function_name (t);
  791.   
  792.   OB_PUTC ('(');
  793.  
  794.   if (parmtypes)
  795.     dump_type (parmtypes, v);
  796.   else
  797.     OB_PUTS ("...");
  798.  
  799.   OB_PUTC (')');
  800.  
  801.   if (v && ! IDENTIFIER_TYPENAME_P (name))
  802.     dump_type_suffix (TREE_TYPE (fntype), 1);
  803.  
  804.   if (TREE_CODE (fntype) == METHOD_TYPE)
  805.     {
  806.       if (IS_SIGNATURE (cname))
  807.     /* We look at the type pointed to by the `optr' field of `this.'  */
  808.     dump_readonly_or_volatile
  809.       (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
  810.       else
  811.     dump_readonly_or_volatile
  812.       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
  813.     }
  814. }
  815.  
  816. /* Handle the function name for a FUNCTION_DECL node, grokking operators
  817.    and destructors properly.  */
  818. static void
  819. dump_function_name (t)
  820.      tree t;
  821. {
  822.   tree name = DECL_NAME (t);
  823.  
  824.   /* There ought to be a better way to find out whether or not something is
  825.      a destructor.  */
  826.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t)))
  827.     {
  828.       OB_PUTC ('~');
  829.       dump_decl (name, 0);
  830.     }
  831.   else if (IDENTIFIER_TYPENAME_P (name))
  832.     {
  833.       /* This cannot use the hack that the operator's return
  834.      type is stashed off of its name because it may be
  835.      used for error reporting.  In the case of conflicting
  836.      declarations, both will have the same name, yet
  837.      the types will be different, hence the TREE_TYPE field
  838.      of the first name will be clobbered by the second.  */
  839.       OB_PUTS ("operator ");
  840.       dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
  841.     }
  842.   else if (IDENTIFIER_OPNAME_P (name))
  843.     {
  844.       char *name_string = operator_name_string (name);
  845.       OB_PUTS ("operator ");
  846.       OB_PUTCP (name_string);
  847.     }
  848.   else
  849.     dump_decl (name, 0);
  850. }
  851.  
  852. static void
  853. dump_char (c)
  854.      char c;
  855. {
  856.   switch (c)
  857.     {
  858.     case TARGET_NEWLINE:
  859.       OB_PUTS ("\\n");
  860.       break;
  861.     case TARGET_TAB:
  862.       OB_PUTS ("\\t");
  863.       break;
  864.     case TARGET_VT:
  865.       OB_PUTS ("\\v");
  866.       break;
  867.     case TARGET_BS:
  868.       OB_PUTS ("\\b");
  869.       break;
  870.     case TARGET_CR:
  871.       OB_PUTS ("\\r");
  872.       break;
  873.     case TARGET_FF:
  874.       OB_PUTS ("\\f");
  875.       break;
  876.     case TARGET_BELL:
  877.       OB_PUTS ("\\a");
  878.       break;
  879.     case '\\':
  880.       OB_PUTS ("\\\\");
  881.       break;
  882.     case '\'':
  883.       OB_PUTS ("\\'");
  884.       break;
  885.     case '\"':
  886.       OB_PUTS ("\\\"");
  887.       break;
  888.     default:
  889.       if (isprint (c))
  890.     OB_PUTC (c);
  891.       else
  892.     {
  893.       sprintf (digit_buffer, "\\%03o", (int) c);
  894.       OB_PUTCP (digit_buffer);
  895.     }
  896.     }
  897. }
  898.  
  899. /* Print out a list of initializers (subr of dump_expr) */
  900. static void
  901. dump_expr_list (l)
  902.      tree l;
  903. {
  904.   while (l)
  905.     {
  906.       dump_expr (TREE_VALUE (l), 0);
  907.       if (TREE_CHAIN (l))
  908.     OB_PUTC2 (',', ' ');
  909.       l = TREE_CHAIN (l);
  910.     }
  911. }
  912.  
  913. /* Print out an expression */
  914. static void
  915. dump_expr (t, nop)
  916.      tree t;
  917.      int nop;            /* suppress parens */
  918. {
  919.   switch (TREE_CODE (t))
  920.     {
  921.     case VAR_DECL:
  922.     case PARM_DECL:
  923.     case FIELD_DECL:
  924.     case CONST_DECL:
  925.     case FUNCTION_DECL:
  926.       dump_decl (t, -1);
  927.       break;
  928.  
  929.     case INTEGER_CST:
  930.       {
  931.     tree type = TREE_TYPE (t);
  932.     my_friendly_assert (type != 0, 81);
  933.  
  934.     /* If it's an enum, output its tag, rather than its value.  */
  935.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  936.       {
  937.         char *p = enum_name_string (t, type);
  938.         OB_PUTCP (p);
  939.       }
  940.     else if (type == boolean_type_node)
  941.       {
  942.         if (t == boolean_false_node)
  943.           OB_PUTS ("false");
  944.         else if (t == boolean_true_node)
  945.           OB_PUTS ("true");
  946.         else
  947.           my_friendly_abort (366);
  948.       }
  949.     else if (type == char_type_node)
  950.       {
  951.         OB_PUTC ('\'');
  952.         dump_char (TREE_INT_CST_LOW (t));
  953.         OB_PUTC ('\'');
  954.       }
  955.     else if (TREE_INT_CST_HIGH (t)
  956.          != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
  957.       {
  958.         tree val = t;
  959.         if (TREE_INT_CST_HIGH (val) < 0)
  960.           {
  961.         OB_PUTC ('-');
  962.         val = build_int_2 (~TREE_INT_CST_LOW (val),
  963.                    -TREE_INT_CST_HIGH (val));
  964.           }
  965.         /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
  966.            systems?  */
  967.         {
  968.           static char format[10]; /* "%x%09999x\0" */
  969.           if (!format[0])
  970.         sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
  971.           sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
  972.                TREE_INT_CST_LOW (val));
  973.           OB_PUTCP (digit_buffer);
  974.         }
  975.       }
  976.     else
  977.       OB_PUTI (TREE_INT_CST_LOW (t));
  978.       }
  979.       break;
  980.  
  981.     case REAL_CST:
  982. #ifndef REAL_IS_NOT_DOUBLE
  983.       sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
  984. #else
  985.       {
  986.     unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
  987.     int i;
  988.     strcpy (digit_buffer, "0x");
  989.     for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
  990.       sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
  991.       }
  992. #endif
  993.       OB_PUTCP (digit_buffer);
  994.       break;
  995.  
  996.     case STRING_CST:
  997.       {
  998.     char *p = TREE_STRING_POINTER (t);
  999.     int len = TREE_STRING_LENGTH (t) - 1;
  1000.     int i;
  1001.  
  1002.     OB_PUTC ('\"');
  1003.     for (i = 0; i < len; i++)
  1004.       dump_char (p[i]);
  1005.     OB_PUTC ('\"');
  1006.       }
  1007.       break;
  1008.  
  1009.     case COMPOUND_EXPR:
  1010.       dump_binary_op (",", t);
  1011.       break;
  1012.  
  1013.     case COND_EXPR:
  1014.       OB_PUTC ('(');
  1015.       dump_expr (TREE_OPERAND (t, 0), 0);
  1016.       OB_PUTS (" ? ");
  1017.       dump_expr (TREE_OPERAND (t, 1), 0);
  1018.       OB_PUTS (" : ");
  1019.       dump_expr (TREE_OPERAND (t, 2), 0);
  1020.       OB_PUTC (')');
  1021.       break;
  1022.  
  1023.     case SAVE_EXPR:
  1024.       if (TREE_HAS_CONSTRUCTOR (t))
  1025.     {
  1026.       OB_PUTS ("new ");
  1027.       dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
  1028.       PARM_DECL_EXPR (t) = 1;
  1029.     }
  1030.       else
  1031.     {
  1032.       dump_expr (TREE_OPERAND (t, 0), 0);
  1033.     }
  1034.       break;
  1035.  
  1036.     case NEW_EXPR:
  1037.       OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
  1038.       OB_PUTC ('(');
  1039.       dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  1040.       OB_PUTC (')');
  1041.       break;
  1042.  
  1043.     case CALL_EXPR:
  1044.       {
  1045.     tree fn = TREE_OPERAND (t, 0);
  1046.     tree args = TREE_OPERAND (t, 1);
  1047.     
  1048.     if (TREE_CODE (fn) == ADDR_EXPR)
  1049.       fn = TREE_OPERAND (fn, 0);
  1050.  
  1051.     if (NEXT_CODE (fn) == METHOD_TYPE)
  1052.       {
  1053.         tree ob = TREE_VALUE (args);
  1054.         if (TREE_CODE (ob) == ADDR_EXPR)
  1055.           {
  1056.         dump_expr (TREE_OPERAND (ob, 0), 0);
  1057.         OB_PUTC ('.');
  1058.           }
  1059.         else if (TREE_CODE (ob) != PARM_DECL
  1060.              || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
  1061.           {
  1062.         dump_expr (ob, 0);
  1063.         OB_PUTC2 ('-', '>');
  1064.           }
  1065.         args = TREE_CHAIN (args);
  1066.       }
  1067.     dump_expr (fn, 0);
  1068.     OB_PUTC('(');
  1069.     dump_expr_list (args);
  1070.     OB_PUTC (')');
  1071.       }
  1072.       break;
  1073.  
  1074.     case WITH_CLEANUP_EXPR:
  1075.       /* Note that this only works for G++ cleanups.  If somebody
  1076.      builds a general cleanup, there's no way to represent it.  */
  1077.       dump_expr (TREE_OPERAND (t, 0), 0);
  1078.       break;
  1079.  
  1080.     case TARGET_EXPR:
  1081.       /* Note that this only works for G++ target exprs.  If somebody
  1082.      builds a general TARGET_EXPR, there's no way to represent that
  1083.      it initializes anything other that the parameter slot for the
  1084.      default argument.  Note we may have cleared out the first
  1085.      operand in expand_expr, so don't go killing ourselves.  */
  1086.       if (TREE_OPERAND (t, 1))
  1087.     dump_expr (TREE_OPERAND (t, 1), 0);
  1088.       break;
  1089.  
  1090.     case MODIFY_EXPR:
  1091.     case PLUS_EXPR:
  1092.     case MINUS_EXPR:
  1093.     case MULT_EXPR:
  1094.     case TRUNC_DIV_EXPR:
  1095.     case TRUNC_MOD_EXPR:
  1096.     case MIN_EXPR:
  1097.     case MAX_EXPR:
  1098.     case LSHIFT_EXPR:
  1099.     case RSHIFT_EXPR:
  1100.     case BIT_IOR_EXPR:
  1101.     case BIT_XOR_EXPR:
  1102.     case BIT_AND_EXPR:
  1103.     case BIT_ANDTC_EXPR:
  1104.     case TRUTH_ANDIF_EXPR:
  1105.     case TRUTH_ORIF_EXPR:
  1106.     case LT_EXPR:
  1107.     case LE_EXPR:
  1108.     case GT_EXPR:
  1109.     case GE_EXPR:
  1110.     case EQ_EXPR:
  1111.     case NE_EXPR:
  1112.       dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
  1113.       break;
  1114.  
  1115.     case CEIL_DIV_EXPR:
  1116.     case FLOOR_DIV_EXPR:
  1117.     case ROUND_DIV_EXPR:
  1118.       dump_binary_op ("/", t);
  1119.       break;
  1120.  
  1121.     case CEIL_MOD_EXPR:
  1122.     case FLOOR_MOD_EXPR:
  1123.     case ROUND_MOD_EXPR:
  1124.       dump_binary_op ("%", t);
  1125.       break;
  1126.  
  1127.     case COMPONENT_REF:
  1128.       {
  1129.     tree ob = TREE_OPERAND (t, 0);
  1130.     if (TREE_CODE (ob) == INDIRECT_REF)
  1131.       {
  1132.         ob = TREE_OPERAND (ob, 0);
  1133.         if (TREE_CODE (ob) != PARM_DECL
  1134.         || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
  1135.           {
  1136.         dump_expr (ob, 0);
  1137.         OB_PUTC2 ('-', '>');
  1138.           }
  1139.       }
  1140.     else
  1141.       {
  1142.         dump_expr (ob, 0);
  1143.         OB_PUTC ('.');
  1144.       }
  1145.     dump_expr (TREE_OPERAND (t, 1), 1);
  1146.       }
  1147.       break;
  1148.  
  1149.     case ARRAY_REF:
  1150.       dump_expr (TREE_OPERAND (t, 0), 0);
  1151.       OB_PUTC ('[');
  1152.       dump_expr (TREE_OPERAND (t, 1), 0);
  1153.       OB_PUTC (']');
  1154.       break;
  1155.  
  1156.     case CONVERT_EXPR:
  1157.       dump_unary_op ("+", t, nop);
  1158.       break;
  1159.  
  1160.     case ADDR_EXPR:
  1161.       if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
  1162.       || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
  1163.     dump_expr (TREE_OPERAND (t, 0), 0);
  1164.       else
  1165.     dump_unary_op ("&", t, nop);
  1166.       break;
  1167.  
  1168.     case INDIRECT_REF:
  1169.       if (TREE_HAS_CONSTRUCTOR (t))
  1170.     {
  1171.       t = TREE_OPERAND (t, 0);
  1172.       my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
  1173.       dump_expr (TREE_OPERAND (t, 0), 0);
  1174.       OB_PUTC ('(');
  1175.       dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  1176.       OB_PUTC (')');
  1177.     }
  1178.       else
  1179.     {
  1180.       if (NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
  1181.         dump_expr (TREE_OPERAND (t, 0), nop);
  1182.       else
  1183.         dump_unary_op ("*", t, nop);
  1184.     }
  1185.       break;
  1186.  
  1187.     case NEGATE_EXPR:
  1188.     case BIT_NOT_EXPR:
  1189.     case TRUTH_NOT_EXPR:
  1190.     case PREDECREMENT_EXPR:
  1191.     case PREINCREMENT_EXPR:
  1192.       dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
  1193.       break;
  1194.  
  1195.     case POSTDECREMENT_EXPR:
  1196.     case POSTINCREMENT_EXPR:
  1197.       OB_PUTC ('(');
  1198.       dump_expr (TREE_OPERAND (t, 0), 0);
  1199.       OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
  1200.       OB_PUTC (')');
  1201.       break;
  1202.  
  1203.     case NON_LVALUE_EXPR:
  1204.       /* FIXME: This is a KLUDGE workaround for a parsing problem.  There
  1205.      should be another level of INDIRECT_REF so that I don't have to do
  1206.      this.  */
  1207.       if (NEXT_CODE (t) == POINTER_TYPE)
  1208.     {
  1209.       tree next = TREE_TYPE (TREE_TYPE (t));
  1210.  
  1211.       while (TREE_CODE (next) == POINTER_TYPE)
  1212.         next = TREE_TYPE (next);
  1213.       
  1214.       if (TREE_CODE (next) == FUNCTION_TYPE)
  1215.         {
  1216.           if (!nop) OB_PUTC ('(');
  1217.           OB_PUTC ('*');
  1218.           dump_expr (TREE_OPERAND (t, 0), 1);
  1219.           if (!nop) OB_PUTC (')');
  1220.           break;
  1221.         }
  1222.       /* else FALLTHRU */
  1223.     }
  1224.       dump_expr (TREE_OPERAND (t, 0), 0);
  1225.       break;
  1226.  
  1227.     case NOP_EXPR:
  1228.       dump_expr (TREE_OPERAND (t, 0), nop);
  1229.       break;
  1230.  
  1231.     case CONSTRUCTOR:
  1232.       OB_PUTC ('{');
  1233.       dump_expr_list (CONSTRUCTOR_ELTS (t), 0);
  1234.       OB_PUTC ('}');
  1235.       break;
  1236.  
  1237.     case OFFSET_REF:
  1238.       {
  1239.     tree ob = TREE_OPERAND (t, 0);
  1240.     if (TREE_CODE (ob) == NOP_EXPR
  1241.         && TREE_OPERAND (ob, 0) == error_mark_node
  1242.         && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
  1243.         /* A::f */
  1244.       dump_expr (TREE_OPERAND (t, 1), 0);
  1245.     else
  1246.       {
  1247.         sorry ("operand of OFFSET_REF not understood");
  1248.         goto error;
  1249.       }
  1250.     break;
  1251.       }
  1252.  
  1253.     case TREE_LIST:
  1254.       if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
  1255.     {
  1256.       OB_PUTID (DECL_NAME (TREE_VALUE (t)));
  1257.       break;
  1258.     }
  1259.       /* else fall through */    
  1260.  
  1261.       /*  This list is incomplete, but should suffice for now.
  1262.       It is very important that `sorry' does not call
  1263.       `report_error_function'.  That could cause an infinite loop.  */
  1264.     default:
  1265.       sorry ("`%s' not supported by dump_expr",
  1266.          tree_code_name[(int) TREE_CODE (t)]);
  1267.  
  1268.       /* fall through to ERROR_MARK...  */
  1269.     case ERROR_MARK:
  1270.     error:
  1271.       OB_PUTCP ("{error}");
  1272.       break;
  1273.     }
  1274. }
  1275.  
  1276. static void
  1277. dump_binary_op (opstring, t)
  1278.      char *opstring;
  1279.      tree t;
  1280. {
  1281.   OB_PUTC ('(');
  1282.   dump_expr (TREE_OPERAND (t, 0), 1);
  1283.   OB_PUTC (' ');
  1284.   OB_PUTCP (opstring);
  1285.   OB_PUTC (' ');
  1286.   dump_expr (TREE_OPERAND (t, 1), 1);
  1287.   OB_PUTC (')');
  1288. }
  1289.  
  1290. static void
  1291. dump_unary_op (opstring, t, nop)
  1292.      char *opstring;
  1293.      tree t;
  1294.      int nop;
  1295. {
  1296.   if (!nop) OB_PUTC ('(');
  1297.   OB_PUTCP (opstring);
  1298.   dump_expr (TREE_OPERAND (t, 0), 1);
  1299.   if (!nop) OB_PUTC (')');
  1300. }
  1301.  
  1302. char *
  1303. fndecl_as_string (cname, fndecl, print_ret_type_p)
  1304.      tree cname, fndecl;
  1305.      int print_ret_type_p;
  1306. {
  1307.   return decl_as_string (fndecl, print_ret_type_p);
  1308. }
  1309.  
  1310. /* Same, but handtype a _TYPE.
  1311.    Called from convert_to_reference, mangle_class_name_for_template,
  1312.    build_unary_op, and GNU_xref_decl.  */
  1313. char *
  1314. type_as_string (typ, v)
  1315.      tree typ;
  1316.      int v;
  1317. {
  1318.   OB_INIT ();
  1319.  
  1320.   dump_type (typ, v);
  1321.  
  1322.   OB_FINISH ();
  1323.  
  1324.   return (char *)obstack_base (&scratch_obstack);
  1325. }
  1326.  
  1327. char *
  1328. expr_as_string (decl, v)
  1329.      tree decl;
  1330.      int v;
  1331. {
  1332.   OB_INIT ();
  1333.  
  1334.   dump_expr (decl, 1);
  1335.  
  1336.   OB_FINISH ();
  1337.  
  1338.   return (char *)obstack_base (&scratch_obstack);
  1339. }
  1340.  
  1341. /* A cross between type_as_string and fndecl_as_string.
  1342.    Only called from substitute_nice_name.  */
  1343. char *
  1344. decl_as_string (decl, v)
  1345.      tree decl;
  1346.      int v;
  1347. {
  1348.   OB_INIT ();
  1349.  
  1350.   dump_decl (decl, v);
  1351.  
  1352.   OB_FINISH ();
  1353.  
  1354.   return (char *)obstack_base (&scratch_obstack);
  1355. }
  1356.  
  1357. char *
  1358. cp_file_of (t)
  1359.      tree t;
  1360. {
  1361.   if (TREE_CODE (t) == PARM_DECL)
  1362.     return DECL_SOURCE_FILE (DECL_CONTEXT (t));
  1363.   else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
  1364.     return DECL_SOURCE_FILE (TYPE_NAME (t));
  1365.   else
  1366.     return DECL_SOURCE_FILE (t);
  1367. }
  1368.  
  1369. int
  1370. cp_line_of (t)
  1371.      tree t;
  1372. {
  1373.   int line = 0;
  1374.   if (TREE_CODE (t) == PARM_DECL)
  1375.     line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
  1376.   if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
  1377.     t = TREE_TYPE (t);
  1378.  
  1379.   if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
  1380.     {
  1381.       if (IS_AGGR_TYPE (t))
  1382.     line = CLASSTYPE_SOURCE_LINE (t);
  1383.       else
  1384.     line = DECL_SOURCE_LINE (TYPE_NAME (t));
  1385.     }
  1386.   else
  1387.     line = DECL_SOURCE_LINE (t);
  1388.  
  1389.   if (line == 0)
  1390.     return lineno;
  1391.  
  1392.   return line;
  1393. }
  1394.  
  1395. char *
  1396. code_as_string (c, v)
  1397.      enum tree_code c;
  1398.      int v;
  1399. {
  1400.   return tree_code_name [c];
  1401. }
  1402.  
  1403. char *
  1404. language_as_string (c, v)
  1405.      enum languages c;
  1406.      int v;
  1407. {
  1408.   switch (c)
  1409.     {
  1410.     case lang_c:
  1411.       return "C";
  1412.  
  1413.     case lang_cplusplus:
  1414.       return "C++";
  1415.  
  1416.     default:
  1417.       my_friendly_abort (355);
  1418.       return 0;
  1419.     }
  1420. }
  1421.  
  1422. /* Return the proper printed version of a parameter to a C++ function.  */
  1423. char *
  1424. parm_as_string (p, v)
  1425.      int p, v;
  1426. {
  1427.   if (p < 0)
  1428.     return "`this'";
  1429.  
  1430.   sprintf (digit_buffer, "%d", p+1);
  1431.   return digit_buffer;
  1432. }
  1433.  
  1434. char *
  1435. op_as_string (p, v)
  1436.      enum tree_code p;
  1437.      int v;
  1438. {
  1439.   static char buf[] = "operator                ";
  1440.  
  1441.   if (p == 0)
  1442.     return "{unknown}";
  1443.   
  1444.   strcpy (buf + 9, opname_tab [p]);
  1445.   return buf;
  1446. }
  1447.  
  1448. char *
  1449. args_as_string (p, v)
  1450.      tree p;
  1451.      int v;
  1452. {
  1453.   if (p == NULL_TREE)
  1454.     return "...";
  1455.  
  1456.   return type_as_string (p, v);
  1457. }
  1458.